const axios = require("axios");

const instance = axios.create({
  timeout: 10000, // 设置超时时间
  headers: {
    "Content-Type": "application/json",
  },
});

const post = async (url, data) => {
  try {
    const response = await instance.post(url, data);
    console.log("POST 请求成功:", JSON.stringify(response.data));
    return response.data;
  } catch (error) {
    console.error("POST 请求失败:", error);
    throw error;
  }
};

const get = async (url) => {
  try {
    const response = await instance.get(url);
    return response.data;
  } catch (error) {
    console.error("GET 请求失败:", error);
    throw error;
  }
};

module.exports = {
  post,
  get,
};
